package com.hnust.root.common.base.response;

/**
 * 统一返回相应参数实体类
 * @author liugh 53182347@qq.com
 */

import lombok.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;

@Data
@ToString
public class BaseResult<T> implements Serializable {
    private static final long serialVersionUID = -1241360949457314497L;
    //是否请求成功
    private int status;
    //返回的实体数据
    private T data;
    //返回的简略信息
    private String msg;
    //业务码
    private int code;

    public BaseResult(int status,int code,String msg,T data) {
        HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
                .getResponse();
        response.setCharacterEncoding("UTF-8");
        this.status = status;
        this.msg = msg;
        this.data = data;
        this.code = code;
    }
}
